﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace Sample.Database.Structure.Interface
{
    public interface IRepository<TContent> : IDisposable where TContent : class
    {
        IQueryable<TContent> All { get; }
        /// <summary>
        /// Saves changes on given context against Database
        /// </summary>
        void SaveChanges();
        /// <summary>
        /// Adds content to the context
        /// </summary>
        /// <param name="content">content</param>
        void Add(TContent content);
        /// <summary>
        /// Deletes content from the context
        /// </summary>
        /// <param name="content">content</param>
        void Delete(TContent content);
        /// <summary>
        /// Deletes content or entities from the context based on given predicate
        /// </summary>
        /// <param name="predicate">where clause</param>
        void Delete(Expression<Func<TContent, bool>> predicate);
        /// <summary>
        /// Finds content based on given predicate
        /// </summary>
        /// <param name="predicate">where clause</param>
        /// <returns>IQueryable of entities</returns>
        IQueryable<TContent> Find(Expression<Func<TContent, bool>> predicate);
        /// <summary>
        /// Gets single content
        /// </summary>
        /// <param name="predicate">where clause</param>
        /// <returns>Only one content</returns>
        TContent Single(Expression<Func<TContent, bool>> predicate);
        /// <summary>
        /// Gets first content
        /// </summary>
        /// <param name="predicate">where clause</param>
        /// <returns>First content</returns>
        TContent First(Expression<Func<TContent, bool>> predicate);
        /// <summary>
        /// Gets count
        /// </summary>
        /// <returns>count of entities</returns>
        int Count();
        /// <summary>
        /// Gets count based on given criteria
        /// </summary>
        /// <param name="criteria">where clause</param>
        /// <returns>count of entities</returns>
        int Count(Expression<Func<TContent, bool>> criteria);
    }
}